import useSWR from "swr";
import { useEffect, useState } from "react";
export const PRICE_DECIMALS = 30; // In-contract price accuracy

export async function fetchAccountPoints({ account }) {
  const url = `${process.env.REACT_APP_API_URL}/air_drop?account=${account}`;
  const response = await fetch(url);

  return response;
}
export function useAccountPoints({ account }) {
  const { data } = useSWR(["useLeaderboardData", account], {
    fetcher: async () => {
      const result = await fetchAccountPoints({ account });
      return result.json();
    },
    refreshInterval: 1000 * 60 * 60
  });

  const [result, setResult] = useState([]);
  useEffect(() => {
    setResult(data);
  }, [data, account]);

  return { data: result || [] };
}
